import 'package:flutter/material.dart';
import 'package:flutter_stort/config/routes.dart';
import 'package:flutter_stort/utils/jump_util.dart';

class PersonPage extends StatefulWidget {
  @override
  _PersonPageState createState() => _PersonPageState();
}

class _PersonPageState extends State<PersonPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(
          "我的",
          style: TextStyle(
            fontSize: 20,
          ),
        ),
      ),
      body: ListView(
        children: [
          _topHeader(),
          _orderType(),
          _actionList(context),
        ],
      ),
    );
  }

  ///头部图片
  Widget _topHeader() {
    return Container(
      height: 160,
      width: double.infinity,
      child: Image.asset("images/icon_loading.png"),
    );
  }

  ///订单状态
  Widget _orderType() {
    return Container(
      color: Colors.white,
      margin: EdgeInsets.only(top: 10),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Expanded(
            flex: 1,
            child: InkWell(
              onTap: () {},
              child: Container(
                height: 60,
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Icon(IconData(0xe632, fontFamily: 'MyIcons3'), size: 22),
                    SizedBox(height: 6),
                    Text("待付款", style: TextStyle(fontSize: 14)),
                  ],
                ),
              ),
            ),
          ),
          Expanded(
            flex: 1,
            child: InkWell(
              onTap: () {},
              child: Container(
                height: 60,
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Icon(IconData(0xe63e, fontFamily: 'MyIcons3'), size: 22),
                    SizedBox(height: 6),
                    Text("待发货", style: TextStyle(fontSize: 14)),
                  ],
                ),
              ),
            ),
          ),
          Expanded(
            flex: 1,
            child: InkWell(
              onTap: () {},
              child: Container(
                height: 60,
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Icon(IconData(0xe620, fontFamily: 'MyIcons3'), size: 22),
                    SizedBox(height: 6),
                    Text("已发货", style: TextStyle(fontSize: 14)),
                  ],
                ),
              ),
            ),
          ),
          Expanded(
            flex: 1,
            child: InkWell(
              onTap: () {},
              child: Container(
                height: 60,
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Icon(IconData(0xe6d7, fontFamily: 'MyIcons3'), size: 22),
                    SizedBox(height: 6),
                    Text("已完成", style: TextStyle(fontSize: 14)),
                  ],
                ),
              ),
            ),
          ),
          Expanded(
            flex: 1,
            child: InkWell(
              onTap: () {},
              child: Container(
                height: 60,
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Icon(
                      Icons.assignment,
                      size: 22,
                      color: Colors.grey,
                    ),
                    SizedBox(height: 6),
                    Text("全部", style: TextStyle(fontSize: 14)),
                  ],
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }

  Widget _actionList(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(top: 10),
      child: Column(
        children: [
          _listItemView(
            title: "收货地址",
            icons: IconData(0xe60d, fontFamily: 'MyIcons3'),
            onClick: () => JumpPageUtils.startNext(
                context, RoutesUtils.SHIPPING_ADDRESS_ROOT),
          ),
          _listItemView(
            title: "我的收藏",
            icons: Icons.star_border,
            onClick: () =>
                JumpPageUtils.startNext(context, RoutesUtils.COLLECT_ROOT),
          ),
          _listItemView(
            title: "我的积分",
            icons: IconData(0xe624, fontFamily: 'MyIcons3'),
            onClick: () =>
                JumpPageUtils.startNext(context, RoutesUtils.INTEGRAL_ROOT),
          ),
          _listItemView(
            title: "我的优惠券",
            icons: IconData(0xe645, fontFamily: 'MyIcons3'),
            onClick: () =>
                JumpPageUtils.startNext(context, RoutesUtils.COUPON_ROOT),
          ),
          _listItemView(
            title: "我的礼物",
            icons: IconData(0xe60b, fontFamily: 'MyIcons3'),
            onClick: () =>
                JumpPageUtils.startNext(context, RoutesUtils.PRESENT_ROOT),
          ),
          _listItemView(
            title: "设置",
            icons: Icons.settings,
            onClick: () =>
                JumpPageUtils.startNext(context, RoutesUtils.SETTING_ROOT),
          ),
        ],
      ),
    );
  }

  ///列表项
  Widget _listItemView({
    String title,
    IconData icons,
    double topMargin = 0,
    GestureTapCallback onClick,
  }) {
    return Container(
      margin: EdgeInsets.only(top: topMargin),
      padding: EdgeInsets.all(10),
      height: 50,
      child: InkWell(
        onTap: onClick,
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Icon(
              icons,
              size: 22,
              color: Colors.grey,
            ),
            SizedBox(width: 10),
            Expanded(
              flex: 1,
              child: Text(
                title,
                style: TextStyle(
                  color: Colors.black,
                  fontSize: 16,
                ),
              ),
            ),
            Icon(
              Icons.navigate_next,
              size: 20,
              color: Colors.grey,
            ),
          ],
        ),
      ),
      decoration: BoxDecoration(
        color: Colors.white,
        border: Border(
          bottom: BorderSide(
            color: Colors.grey,
            width: 0.5,
            style: BorderStyle.solid,
          ),
        ),
      ),
    );
  }
}
